#include "../comm.h"
class Solution {
public:
    int kthLargestValue(vector<vector<int>>& matrix, int k) {
        int n = matrix.size(), m = matrix[0].size();
        vector<vector<int>> s(n + 1, vector<int>(m + 1, 0));
        vector<int> v;
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= m; ++j)
            {
                s[i][j] = s[i - 1][j] ^ s[i][j - 1] ^ s[i - 1][j - 1] ^ matrix[i - 1][j - 1];
                v.push_back(s[i][j]);
            }
        // 快速选择
        nth_element(v.begin(), v.begin() + k - 1, v.end(), greater<int>());
        return v[k - 1];
    }
};